package com.morontestandroid;


import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsoluteLayout;
import android.widget.ImageView;
import android.widget.TextView;

public class ThirdLevel extends Activity implements android.view.View.OnClickListener {
	ImageView bear1, bear2, bear3, bear4, bear5, bg;
	boolean bear1clicked, bear2clicked, bear3clicked, bear4clicked,
			bear5clicked;
	Chronometer mChronometer;
	TextView question;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.third_level);
		mChronometer = (Chronometer) findViewById(R.id.thirdlevelChrmId);
        bear1 = (ImageView) findViewById(R.id.bear1);
        bear2 = (ImageView) findViewById(R.id.bear2);
        bear3 = (ImageView) findViewById(R.id.bear3);
        bear4 = (ImageView) findViewById(R.id.bear4);
        bear5 = (ImageView) findViewById(R.id.bear5);
        bg    = (ImageView) findViewById(R.id.imageView2);
        question = (TextView) findViewById(R.id.level3QuestionId);
        
        mChronometer.setBase(getTime()); 
        mChronometer.start();
        
        bear1clicked = false;
        bear2clicked = false;
        bear3clicked = false;
        bear4clicked = false;
        bear5clicked = false;
             
        bear1.setOnClickListener(this);
        bear2.setOnClickListener(this);
        bear3.setOnClickListener(this);
        bear4.setOnClickListener(this);
        bear5.setOnClickListener(this);
        bg.setOnClickListener(this);
        bear1.bringToFront();
   
	       Typeface font = Typeface.createFromAsset(getAssets(), "testtext.ttf");  
	        question.setTypeface(font);
   
	}
	
	 public long getTime() {
		  Bundle extras = getIntent().getExtras();
		  long time = extras.getLong("time");
		  return time;
		 
	 }
	
	@Override
	public void onClick(View view) {
		if(view.getId()==R.id.imageView2){
			startActivity(new Intent(this, FailActivity.class));
		}
		if(view.getId()==R.id.bear1) {
			hideBear1();
			question.setVisibility(View.INVISIBLE);//hide the text.
			bear2.bringToFront();
			bear1clicked = true;
		}
		if(view.getId()==R.id.bear2 && bear1clicked){
			bear2clicked = true;
			hideBear2();
			bear3.bringToFront();
			setLocation(375,250);
		}
		
		if(view.getId()==R.id.bear3 && bear2clicked){
			bear3clicked = true;
			hideBear3();
			bear4.bringToFront();
		}
		if(view.getId()==R.id.bear4 && bear3clicked){
			bear4clicked = true;
			hideBear4();
			bear5.bringToFront();
		}
		
		if(view.getId()==R.id.bear5 && bear4clicked){
		
			hideBear5();
			int activityID = 1;
			   Intent intent;
			   intent = new Intent().setClass(this, FourthLevel.class);
			   intent.putExtra("time", getThisBase());
			   startActivityForResult(intent, activityID);
		}
		
	
	}
	
	private void setLocation(int x, int y) {
	    final ImageView iv = (ImageView) findViewById(R.id.bear3);
	    final AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams) iv.getLayoutParams();
	    lp.x = x;
	    lp.y = y;
	    iv.setLayoutParams(lp);
	 
	}
	
	private void hideBear1(){
	    final ImageView iv = (ImageView) findViewById(R.id.bear1);
	    final AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams) iv.getLayoutParams();
	    iv.setVisibility(View.GONE);
	}
	private void hideBear2(){
	    final ImageView iv = (ImageView) findViewById(R.id.bear2);
	    final AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams) iv.getLayoutParams();
	    iv.setVisibility(View.GONE);
	}
	private void hideBear3(){
	    final ImageView iv = (ImageView) findViewById(R.id.bear3);
	    final AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams) iv.getLayoutParams();
	    iv.setVisibility(View.GONE);
	}
	private void hideBear4(){
	    final ImageView iv = (ImageView) findViewById(R.id.bear4);
	    final AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams) iv.getLayoutParams();
	    iv.setVisibility(View.GONE);
	}
	private void hideBear5(){
	    final ImageView iv = (ImageView) findViewById(R.id.bear5);
	    final AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams) iv.getLayoutParams();
	    iv.setVisibility(View.GONE);
	}
		
	
	public void onBackPressed() {
		// do something on back
		startActivity(new Intent(this, MenyActivity.class));
		return;
		}
	
	public long getThisBase(){
		  return mChronometer.getBase();
		 }
	
}

